package com.elevator;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

interface layerUIEventListener
{
	public void ActionEvent(int nActionType,Object srcObject);
//	public void BtnActionEvent(int nBtnType,Object srcObject);
}
public class layerUI extends JPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public layerUIEventListener mEventListenerEvent = null;
	public int mLayer = 0; 
	public doorUI mDoorUI = new doorUI(50,60);
	public JButton mUpBtn = null;
	public JButton mDownBtn = null;
	public JLabel mCurrentLayer = new JLabel("G");
	public JLabel mUpLabel = new JLabel("U");
	public JLabel mDownLabel = new JLabel("D");
	public JLabel mCurrentLiftInLayer = new JLabel("G");
	public layerUI()
	{
		this(100, 100);
		
	}
	
	public layerUI(int w,int h)
	{
		this.setLayout(null);
		//this.removeAll()
		mDownBtn = new JButton("D");
		mUpBtn = new JButton("U");
		
		mUpBtn.setSize(20, 20);
		mDownBtn.setSize(20, 20);


		this.add(mDoorUI);
		this.add(mDownBtn);
		this.add(mUpBtn);
		this.add(mCurrentLayer);
		this.add(mCurrentLiftInLayer);
		this.add(mUpLabel);
		this.add(mDownLabel);
		
		mUpBtn.setLocation(75, 50);
		mDownBtn.setLocation(75, 75);
		
		mUpBtn.setMargin(new Insets(0, 0, 0, 0));
		mDownBtn.setMargin(new Insets(0, 0, 0, 0));

//		mUpBtn.addActionListener(new ActionListener() {
//			
//			@Override
//			public void actionPerformed(ActionEvent arg0) {
//				// TODO Auto-generated method stub
//				mEventListenerEvent.BtnActionEvent(1, arg0.getSource());
//			}
//		});
//		mDownBtn.addActionListener(new ActionListener() {
//			
//			@Override
//			public void actionPerformed(ActionEvent arg0) {
//				// TODO Auto-generated method stub
//				mEventListenerEvent.BtnActionEvent(-1, arg0.getSource());
//			}
//		});
		mDoorUI.setLocation(20, 39);
		
		mCurrentLayer.setLocation(80, 0);
		mCurrentLayer.setOpaque(true);
		mCurrentLayer.setBackground(Color.green);
		mCurrentLayer.setHorizontalAlignment(SwingConstants.CENTER);
		mCurrentLayer.setVerticalAlignment(SwingConstants.CENTER);
		mCurrentLayer.setSize(20, 20);
		
		mCurrentLiftInLayer.setLocation(35, 10);
		mCurrentLiftInLayer.setOpaque(true);
		mCurrentLiftInLayer.setBackground(Color.blue);
		mCurrentLiftInLayer.setHorizontalAlignment(SwingConstants.CENTER);
		mCurrentLiftInLayer.setVerticalAlignment(SwingConstants.CENTER);
		mCurrentLiftInLayer.setSize(20, 20);
		
		mUpLabel.setLocation(15, 10);
		//mUpLabel.setOpaque(true);
		//mUpLabel.setBackground(Color.blue);
		mUpLabel.setHorizontalAlignment(SwingConstants.CENTER);
		mUpLabel.setVerticalAlignment(SwingConstants.CENTER);
		mUpLabel.setSize(15, 15);
		mDownLabel.setOpaque(true);
		mDownLabel.setLocation(60, 10);
		//mUpLabel.setOpaque(true);
		//mUpLabel.setBackground(Color.blue);
		mDownLabel.setHorizontalAlignment(SwingConstants.CENTER);
		mDownLabel.setVerticalAlignment(SwingConstants.CENTER);
		mDownLabel.setSize(15, 15);
		mDownLabel.setOpaque(true);
		
		mUpBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				mEventListenerEvent.ActionEvent(1, layerUI.this);
			}
		});
		mDownBtn.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				mEventListenerEvent.ActionEvent(-1, layerUI.this);
			}
		});
		
		this.setSize(w,	h);
	
		
		//mDoorUI.startOpenDoor();
	}
	
	@Override
	public void paint(Graphics g) {
		// TODO Auto-generated method stub
		super.paint(g);
		g.setColor(Color.magenta);
		g.drawRect(0, 0, this.getWidth()-1, this.getHeight()-1);
		

	}
}
